#! /bin/bash
ifmaven=`mvn -version`
maven=$(echo ${ifmaven} | grep "Maven home")
if [[ "$maven" != "" ]]
then
    echo "maven was installed"
else
	echo "--------------begin install maven--------------"
	mavenname="apache-maven-3.6.3"
	wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/${mavenname}-bin.tar.gz
	tar -zxvf ${mavenname}-bin.tar.gz
	basepath="/usr/local"
	installpath=$(cd `dirname $0`; pwd)
	cd ${installpath}
	mv ${mavenname} ${basepath}
	echo "export MAVEN_HOME=${basepath}/${mavenname}" >>/etc/profile
	echo "export PATH=$PATH:$MAVEN_HOME/bin" >>/etc/profile
	source /etc/profile
	cd ${basepath}/${mavenname}/conf
	sed -i "s!<mirrors>!<mirrors>\n<mirror>\n<id>nexus-aliyun</id>\n<mirrorOf>central</mirrorOf>\n<name>Nexus aliyun</name>\n<url>http://maven.aliyun.com/nexus/content/groups/public</url>\n</mirror>!g" settings.xml
	echo "--------------install success!------------"
	echo "if maven environment invalid please execute command: source /etc/profile"
fi